package server;

import java.util.ArrayList;

import server.Message;
import server.Server;


/**
 * Chatroom object
 *
 */
public class Chatroom {

	/**
	 * list of all users (who are live players)
	 */
	private ArrayList<User> userList;
	
	/**
	 * Constructor
	 * @param name : String
	 * @param isPublic : boolean
	 */
	public Chatroom() {
        
        userList = new ArrayList<User>();
        
	}

	/**
	 * Sends text to all users in chatroom 
	 * @param sender
	 * @param text
	 */
	public void textFire(String sender, String text){
		System.out.println("in textfire, user list " + userList.size());
		for (User user : userList) {
			Server.clientWriters.get(user.getUserName()).println(Message.chatMessage(sender, text));
		}
			
	}
	
	/**
	 * Adds a buddy to the chatroom
	 * @param buddy
	 */
	public void addUser(User user) {
		userList.add(user);
	}
	
	/**
	 * Removes a buddy from the chatroom
	 * @param buddy
	 */
	public void removeBuddy(User user) {
		userList.remove(user);
		
	}
	

	/**
	 * Gets the buddylist of the chatroom
	 * @return BuddyList
	 */
	public ArrayList<User> getUserList() {
		return userList;
	}


	
}
